Repository navigation
gh-159041: Fix use-after-free in asyncio task tracking during thread state cleanup - #159073
Conversation
Move lingering asyncio tasks to the interpreter only after all finalizer-capable thread-state cleanup has completed. Also transfer tasks created by finalizers during interpreter shutdown. Add regression tests for both thread-state and interpreter cleanup paths.
|
Ping @colesbury @msullivan since you two have been reviewing asyncio changes recently and Kumar is busy. |
…ove to more appropriate spot
|
Thanks. |
|
Thanks @ngoldbaum for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
|
Thanks @ngoldbaum for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15. |
|
Sorry, @ngoldbaum and @kumaraditya303, I could not cleanly backport this to Please backport manually with cherry_picker, see the devguide for more information. |
|
GH-159694 is a backport of this pull request to the 3.15 branch. |
|
GH-159695 is a backport of this pull request to the 3.14 branch. |
|
Centralize transfer of remaining tasks to the interpreter in free_threadstate(), before normal thread-state unlinking and GIL release. Keep memory deallocation separate for initialization failures and deferred daemon-thread cleanup.
Add regression tests for both thread-state and interpreter cleanup paths.
asyncioTaskcreated from a finalizer duringPyThreadState_Clear()registers into memory that is about to be freed (3.14 regression) #159041